import java.util.Scanner;

public class BankerAlgorithm {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] resource = new int[3];
        for (int i = 0; i < 3; i++) {
            resource[i] = scanner.nextInt();
        }
        int[][] need = new int[5][3];
        String[] processNames = new String[5];
        for (int i = 0; i < 5; i++) {
            processNames[i] = scanner.next();
            for (int j = 0; j < 3; j++) {
                need[i][j] = scanner.nextInt() - scanner.nextInt();
            }
        }
        scanner.close();

        int[] available = resource.clone();
        int[][] allocation = new int[5][3];
        boolean[] finish = new boolean[5];
        while (true) {
            boolean flag = false;
            for (int i = 0; i < 5; i++) {
                if (!finish[i] && check(available, need[i])) {
                    for (int j = 0; j < 3; j++) {
                        available[j] += allocation[i][j];
                        need[i][j] -= allocation[i][j];
                    }
                    finish[i] = true;
                    flag = true;
                }
            }
            if (!flag) {
                break;
            }
        }

        System.out.println(resource[0] + " " + resource[1] + " " + resource[2]);
        for (int i = 0; i < 5; i++) {
            if (!finish[i]) {
                System.out.print(processNames[i] + " ");
                for (int j = 0; j < 3; j++) {
                    System.out.print(need[i][j] + " ");
                }
                System.out.println();
            }
        }
    }

    private static boolean check(int[] available, int[] need) {
        for (int i = 0; i < 3; i++) {
            if (need[i] > available[i]) {
                return false;
            }
        }
        return true;
    }
}
